/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.niedziela12.pai.webservices;

import com.niedziela12.pai.ejb.user.facades.UserFacadeLocal;
import com.niedziela12.pai.ejb.hotel.facades.HotelFacadeLocal;
import com.niedziela12.pai.ejb.reservation.facades.ReservationFacadeLocal;
import com.niedziela12.pai.ejb.room.facades.RoomFacadeLocal;
import java.util.Date;
import java.util.List;
import javax.ejb.EJB;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.ejb.Stateless;

/**
 *
 * @author Kamil
 */
//@WebService(serviceName = "CentralaWebServices")
@Stateless()
public class CentralaWebServices {

    @EJB
    private UserFacadeLocal userBean;
    @EJB
    private ReservationFacadeLocal reservationBean;
    @EJB
    private HotelFacadeLocal hotelBean;
    @EJB
    private RoomFacadeLocal roomBean;
    
    /**
     * This is a sample web service operation
     */
//    @WebMethod(operationName = "hello")
    public String hello(@WebParam(name = "name") String txt) {
        return "Hello " + txt + " !";
    }
    
//    @WebMethod(operationName = "addReservation")
    public boolean addReservation(int roomId, int userId, Date begin, Date end){
        com.niedziela12.pai.ejb.entities.Reservation res = new com.niedziela12.pai.ejb.entities.Reservation();
        res.setUser(userBean.find(userId));
        res.setReservationBegin(begin);
        res.setReservationEnd(end);
        com.niedziela12.pai.ejb.entities.Room room = roomBean.find(roomId);
        res.setRoom(room);
        res.setPrice(room.getPrice());
        res.setConfirmed(true);
        try{
            reservationBean.create(res);
            return true;
        } catch(Exception e){
            
            return false;
        }
    }

//    @WebMethod(operationName = "getAllHotels")
    public List<Integer> getAllHotels(){
        return hotelBean.findAllIds();
    }

//    @WebMethod(operationName = "getAllHotelsInCity")
    public List<Integer> getAllHotelsInCity(String city){
        return hotelBean.findAllHotelsInCity(city);
    }

//    @WebMethod(operationName = "getAllFreeRooms")
    public List<Integer> getAllFreeRooms(int hotelId, Date begin, Date end, int capactiy){
        return roomBean.getAllFreeRooms(hotelId, begin, end, capactiy);
    }
}
